package service.impl.security;

import java.util.ArrayList;
import java.util.List;

import service.impl.BaseDataServiceImpl;
import service.interf.security.IGroupMember;
import dao.interf.IGroupMemberDAO;
import dao.pojo.Group;
import dao.pojo.GroupMember;

public class GroupMemberImpl extends BaseDataServiceImpl implements
		IGroupMember {
	private IGroupMemberDAO groupMemberDAO;

	public IGroupMemberDAO getGroupMemberDAO() {
		return groupMemberDAO;
	}

	public void setGroupMemberDAO(IGroupMemberDAO groupMemberDAO) {
		this.groupMemberDAO = groupMemberDAO;
	}

	// 根据用户的id获取用户所属的组
	public List<Group> getGroupByUserId(Long UserId) {
		List<GroupMember> lst = groupMemberDAO.findByProperties(
				new String[] { "user.userId" }, new Object[] { UserId });
		List<Group> gL = new ArrayList<Group>();
		if (null != lst && !lst.isEmpty())
			for (GroupMember gm : lst)
				gL.add(gm.getGroup());
		return gL;
	}
}
